package com.zmh.arithmetic.linked_list;

/**
 * @author zmh
 * @create 2019-07-23 14:44
 **/
public class MergeTwoList {

      class ListNode {
          int val;
          ListNode next;
          ListNode(int x) { val = x; }
      }

    class Solution {
        public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
            ListNode newNode = new ListNode(-1);
            ListNode currentNode = newNode;
            while (null != l1 && null != l2) {
                if (l1.val < l2.val) {
                    currentNode.next = l1;
                    l1 = l1.next;
                } else {
                    currentNode.next = l2;
                    l2 = l2.next;
                }
                currentNode = currentNode.next;
            }
            if (null == l1) {
                currentNode.next = l2;
            }
            if (null == l2) {
                currentNode.next = l1;
            }

            return newNode.next;
        }
    }
}
